import React, { useState } from 'react';
import { Table } from 'antd';
import { history } from 'umi'
import { genID } from '@/pages/WorkFlow/utils';

const ORGANIZATION_TYPE = {
    1: '集团',
    2: '公司',
    3: '部门',
    4: '事业部'
};

// 变更内容表格
const OrgChangeTable = ({ data = {} }) => {
    const { compareDataField = {} } = data;
    const [dataSource] = useState(compareDataField?.updateInfoList || []);

    const columns = [
        {
            title: '机构名称',
            dataIndex: 'parentPathName',
            render: (text, record) => {
                const { organizationType, organizationCode, organizationPath, organizationName } = record;
                return !organizationCode ? (
                    text
                ) : (
                    <a
                        onClick={e => {
                            e.stopPropagation();
                            history.push({
                                pathname: `/office/personnelManagement/organization/${
                                    organizationType === 3 ? 'departmentinfo' : 'companyinfo'
                                }`,
                                query: {
                                    organizationCode,
                                    organizationPath,
                                    organizationName
                                },
                                state: { tabRoute: true, tabRefresh: true }
                            });
                        }}
                    >
                        {text}
                    </a>
                );
            }
        },
        {
            title: '变更类型',
            dataIndex: 'operationTypeName',
            render: (text, record) => `${text}${ORGANIZATION_TYPE[record.organizationType]}`
        },
        {
            title: '变更动作',
            render: (text, record) => {
                const { operationTypeName, organizationName } = record;
                return `${operationTypeName} ${organizationName}`;
            }
        }
    ];
    return <Table columns={columns} dataSource={dataSource} pagination={false} rowKey={() => genID(6)} />;
};

export default OrgChangeTable;
